package com.principles.create.simplefactory;

/**
 * @Description 简单工厂模式，根据输入工厂的参数，判断生产什么类型的产品
 * @Date 2025/1/26 19:22
 **/
public class SimpleFactory {

    public static Product SimpleFactory(String name){

        if(name.equals("A")){
            return new ProductA();
        }else if(name.equals("B")){
            return new ProductB();

        }else {
            return null;
        }
    }

    public static void main(String[] args) {
        Product a = SimpleFactory.SimpleFactory("A");
        a.create();
    }
}


abstract class Product{
    public abstract void create();
}
class ProductA extends Product{

    @Override
    public void create() {
        System.out.println("创建A");
    }
}
class ProductB extends Product{

    @Override
    public void create() {
        System.out.println("创建B");
    }
}